package com.ugoodtech.mdcc.client.controller;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.ugoodtech.mdcc.client.dto.JsonResponse;
import com.ugoodtech.mdcc.client.service.AliSmsProvider;
import com.ugoodtech.mdcc.client.service.impl.SmsServiceUtil;
import com.ugoodtech.mdcc.core.domain.User;
import com.ugoodtech.mdcc.core.domain.VCode;
import com.ugoodtech.mdcc.core.repository.UserRepository;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "获取验证码")
@RestController
@RequestMapping("/sms")
public class SmsController {
    //    LTAISmTXUDxswBvH
//41DyY1gzJPI0Z9lejCmvZYs0eu73yo
    @Autowired
    private AliSmsProvider aliSmsProvider;

    @Autowired
    private UserRepository userRepository;

    @ApiOperation("获取验证码")
    @RequestMapping(value = "/getCode", method = RequestMethod.POST)
    public JsonResponse getCode(
            @ApiParam("手机号码phone") @RequestParam(value = "phone") String phone
            // @ApiParam("是否为内部用户登录") @RequestParam(value = "isSystem") boolean isSystem
    ) {
        User user = userRepository.findByUserName_phone(phone);
        // if ((isSystem && user.getUserFlag() == 1 ) || (!isSystem && user.getUserFlag() == 0)){
        //     return JsonResponse.errorResponseWithError("错误","未找到该用户");
        // }
        SmsServiceUtil.smsSend(phone, "");
        return null;
    }

//    @ApiOperation("发送短信")
//    @RequestMapping(value = "/sendMsg", method = RequestMethod.GET)
//    public JsonResponse sendMsg() {
//        try {
//            SendSmsResponse sendSmsResponse = aliSmsProvider.sendCustomerMsg("13918614157", "龚浩", "2018-8-1",
//                    "上海市长宁区维修站");
//            return JsonResponse.successResponse();
//        } catch (ClientException e) {
//            e.printStackTrace();
//        }
//        return JsonResponse.errorResponseWithError("Boom","爆炸");
//    }


}
